package com.cloud.pole.rpc;

import java.util.ArrayList;
import java.util.List;
import org.apache.commons.beanutils.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.fastjson.JSON;
import com.cloud.pole.api.msg.MsgNoticeApi;
import com.cloud.pole.common.constant.CommonConstants;
import com.cloud.pole.common.exception.BaseException;
import com.cloud.pole.common.exception.ParamException;
import com.cloud.pole.common.msg.ApiRestResponse;
import com.cloud.pole.common.util.RegexUtils;
import com.cloud.pole.msg.model.entity.MsgNotice;
import com.cloud.pole.msg.service.MsgNoticeService;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RestController
@RequestMapping("api/notice")
public class NoticeRest {
	
	@Autowired
    private MsgNoticeService msgNoticeService;

	@RequestMapping(value = "/getSysNoticeList")
    @ResponseBody
    public ApiRestResponse<List<MsgNoticeApi>> getSysNoticeList(
    		@RequestParam(defaultValue = "1") Integer userType,
    		@RequestParam(defaultValue = "1") Integer pageSize){
		try {
			List<MsgNotice>  srcList = msgNoticeService.getSysNoticeList(userType, pageSize);
			List<MsgNoticeApi> destList = new ArrayList<MsgNoticeApi>();
			if(srcList != null) {
				for(MsgNotice msgNotice : srcList ) {
					MsgNoticeApi msgNoticeApi = new MsgNoticeApi();
					BeanUtils.copyProperties(msgNoticeApi, msgNotice);
					msgNoticeApi.setContent(null);
					destList.add(msgNoticeApi);
				}
			}
			return ApiRestResponse.success(CommonConstants.STATUS_OK_MESSAGE, destList);
		} catch (BaseException e) {
			return ApiRestResponse.fail(e.getStatus(), e.getMessage(), null);
		} catch (Exception e) {
			log.error(CommonConstants.STATUS_ERROR_MESSAGE + "{}", e.getMessage(), e);
			return ApiRestResponse.fail(CommonConstants.STATUS_ERROR_MESSAGE, null);
		}
    }
}
